﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <script type="text/javascript" src="lib/PIE_IE678.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.7/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="lib/icheck/icheck.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <!-- 权限验证 -->
    <script type="text/javascript" src="static/WebApi.js"></script>
    <title>修改员工信息</title>
</head>
<body>
    <div class="page-container">
        <div class="mt-20">
            <div class="Huialert Huialert-info"><i class="icon-remove"></i>员工修改信息提示：员工账号为员工登录账号,员工修改只修改页面有的字段</div>
        </div>
        <form class="form form-horizontal" id="form-admin-upd">
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>员工姓名：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="hidden" id="T_StaffID" name="T_StaffID" />
                    <input type="text" class="input-text" value="" placeholder="请输入员工姓名" id="T_Name" name="T_Name" maxlength="20" required="required">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>性别：</label>
                <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                    <div class="radio-box">
                        <input name="T_Sex" class="radio-box" type="radio" id="T_Sex-1" value="男" checked>
                        <label for="sex-1">男</label>
                    </div>
                    <div class="radio-box">
                        <input type="radio" id="T_Sex-2" name="T_Sex" value="女">
                        <label for="sex-2">女</label>
                    </div>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">身份证号：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="请输入员工身份证号" id="T_IDcard" name="T_IDcard" maxlength="20">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">手机：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="请输入员工手机" id="T_Phone" name="T_Phone" maxlength="11">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">邮箱：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" placeholder="请输入员工邮箱" name="T_Email" id="T_Email">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>员工账号：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="请输入员工账号" id="T_Account" name="T_Account" maxlength="20" required="required">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">角色：</label>
                <div class="formControls col-xs-8 col-sm-9 skin-minimal" id="role">
                    <!--<span class="check-box">
                        <input type="checkbox" value="审核评估登记表" />
                    </span>-->
                    <!--<span class="check-box">
                        <input id="T_RoleID2" class="T_RoleID" name="T_RoleID" type="checkbox" value="身份证明" /><label for="P_assess1">身份证明</label>
                    </span>
                    <span class="check-box">
                        <input id="T_RoleID3" class="T_RoleID" name="T_RoleID" type="checkbox" value="房屋权属" /><label for="P_assess2">房屋权属</label>
                    </span>
                    <span class="check-box">
                        <input id="T_RoleID4" class="T_RoleID" name="T_RoleID" type="checkbox" value="网签合同" /><label for="P_assess3">网签合同</label>
                    </span>-->
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">部门：</label>
                <div class="formControls col-xs-8 col-sm-9 skin-minimal" id="dept">
                    <input type="checkbox" checked="checked" />
                </div>
            </div>
            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                </div>
            </div>
        </form>
    </div>

    <!--基本js脚本-->
    <script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="lib/layer/2.1/layer.js"></script>
    <script type="text/javascript" src="lib/icheck/jquery.icheck.min.js"></script>
    <script type="text/javascript" src="lib/jquery.validation/1.14.0/jquery.validate.min.js"></script>
    <script type="text/javascript" src="lib/jquery.validation/1.14.0/validate-methods.js"></script>
    <script type="text/javascript" src="lib/jquery.validation/1.14.0/messages_zh.min.js"></script>
    <script type="text/javascript" src="static/h-ui/js/H-ui.js"></script>
    <script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script>
    <!--扩展js脚本-->
    <script type="text/javascript" src="static/Common.js"></script>

    <!--请在下方写此页面业务相关的脚本-->
    <script type="text/javascript">

        //页面加载
        $(function () {
            $('.skin-minimal input').iCheck({
                checkboxClass: 'icheckbox-blue',
                radioClass: 'iradio-blue',
                increaseArea: '20%'
            });
            var uri = document.location.search;//接收页面传值
            var i = uri.lastIndexOf("?") + 1;//获取问号前面的值
            var id = uri.substr(i);//截取问号前面的值
            var deptid = [0];
            var roleid = [0];
            $.ajax({
                url: ApiUrl + 'api/Staff/UpdateByid',
                type: 'post',
                data: { "": id },
                async: false,
                success: function (data) {
                    if (data != null) {
                        $("#T_StaffID").val(data.T_StaffID);
                        $("#T_Name").val(data.T_Name);
                        data.T_Sex == "女" ? $("#T_Sex2").attr("checked", "checked") : $("#T_Sex1").attr("checked", "checked");
                        $("#T_IDcard").val(data.T_IDcard);
                        $("#T_Phone").val(data.T_Phone);
                        $("#T_Email").val(data.T_Email);
                        $("#T_Account").val(data.T_Account);
                        deptid = data.T_Department;
                        roleid = data.T_Role;
                    }
                    else {
                        layer.msg("修改取值为空！", { icon: 2, time: 1000 });
                    }
                }
            });
            //加载角色下拉框
            $.ajax({
                type: "post",
                url: ApiUrl + "api/Role/Select",
                data: { "": null },
                success: function (data) {
                    var option = Array();
                    $("#role").empty();
                    $(data).each(function (i, item) {
                        if (item.T_IsSystem != 0) {
                            option.push('<span class="check-box">');
                            if (roleid.indexOf(item.T_RoleID) >= 0) {
                                option.push('<input checked="checked" id="T_RoleID' + i + '" name="T_Role" type="checkbox" value="' + item.T_RoleID + '" /><label for="T_RoleID' + i + '">' + item.T_Rname + '</label>');
                            }
                            else {
                                option.push('<input id="T_RoleID' + i + '" name="T_Role" type="checkbox" value="' + item.T_RoleID + '" /><label for="T_RoleID' + i + '">' + item.T_Rname + '</label>');
                            }
                            option.push('</span>');
                        }
                    });
                    $("#role").append(option.join(""));
                    $('#role input').iCheck({
                        checkboxClass: 'icheckbox-blue',
                        radioClass: 'iradio-blue',
                        increaseArea: '20%'
                    });
                }
            });

            //加载部门下拉框
            $.ajax({
                type: "post",
                url: ApiUrl + "api/Department/Select",
                data: { "": null },
                success: function (data) {
                    var option = Array();
                    $("#dept").empty();
                    $(data).each(function (i, item) {
                        option.push('<span class="check-box">');
                        if (deptid.indexOf(item.T_DepartmentID) >= 0) {
                            option.push('<input checked="checked" id="T_DepartmentID' + i + '" name="T_Department" type="checkbox" value="' + item.T_DepartmentID + '" /><label for="T_DepartmentID' + i + '">' + item.T_Dname + '</label>');
                        } else {
                            option.push('<input id="T_DepartmentID' + i + '" name="T_Department" type="checkbox" value="' + item.T_DepartmentID + '" /><label for="T_DepartmentID' + i + '">' + item.T_Dname + '</label>');
                        }
                        option.push('</span>');
                    });
                    $("#dept").append(option.join(""));
                    $('#dept input').iCheck({
                        checkboxClass: 'icheckbox-blue',
                        radioClass: 'iradio-blue',
                        increaseArea: '20%'
                    });
                }
            });

            //表单提交验证--修改功能
            $("#form-admin-upd").validate({
                rules: {
                    T_Name: {
                        required: true,
                    },
                    T_Account: {
                        required: true,

                    },
                    T_Password: {
                        required: true,
                    },
                    T_Password2: {
                        equalTo: "#T_Password",
                    },
                    T_Email: {
                        email: true
                    }
                },
                onkeyup: false,
                focusCleanup: true,
                success: "valid",
                submitHandler: function () {
                    if ($('#role input[name="T_Role"]:checked').length <= 0) {
                        parent.layer.msg("请选择员工的角色！", { icon: 0, time: 1000 });
                        return false;
                    }
                    if ($('#dept input[name="T_Department"]:checked').length <= 0) {
                        parent.layer.msg("请选择员工所属部门！", { icon: 0, time: 1000 });
                        return false;
                    }
                    $.ajax({
                        url: ApiUrl + 'api/Staff/Update',
                        type: 'post',
                        data: $("#form-admin-upd").serialize(),
                        success: function (data) {
                            if (data == true) {
                                parent.layer.msg("修改员工成功！", { icon: 1, time: 2000 });
                                parent.location.reload();
                            }
                            else {
                                parent.layer.msg("修改员工失败！", { icon: 2, time: 1000 });
                            }
                        }
                    });
                }
            });
        });

    </script>
    <!--/请在上方写此页面业务相关的脚本-->
</body>
</html>
